import QtQuick 2.0

Item {
    id:root
    width: 850
    height: 580
    property real minSize:  Math.min(width/850, height/580)
    property real textSize:  40*minSize

     
    onFocusChanged:{
        if(!focus) return
        refurbishA()
        refurbishB()
    }

    function readModSingal(handle, sqlName, min, max, point)
    {
        var t_var = $sqlMcRecorder.qml_getRegulatorVal_bystr_toint16(sqlName)
        if(t_var >= min && t_var <= max)
            handle.text = String((t_var/Math.pow(10, point)).toFixed(point))
        else
            handle.text = "???"
    }
    function refurbishA()
    {
        readModSingal(diffAdj_a, "A套调差值", -20000, 20000, 3)
    }
    function refurbishB()
    {
        readModSingal(diffAdj_b, "B套调差值", -20000, 20000, 3)
    }

    Text {
        x: 130*root.minSize
        y: 146*root.minSize
        color: "#44F6F6"
        text: qsTr("A通道调差值:")
        font.bold: true
        font.family: "Verdana"
        font.pixelSize: parent.textSize
    }

    TextInput {
        id:diffAdj_a
        x: 450*root.minSize
        y: 146*root.minSize
        color: "#bccc5a"
        validator: RegExpValidator{regExp:/[0-9\.]+/}
        text: qsTr("???")
        selectByMouse: true
        font.bold: true
        font.family: "Verdana"
        font.pixelSize: parent.textSize
    }

    EXC_Normal_BtnUncheckSecret_highStyle {
        id: eXC_Normal_BtnUncheckStyle
        x: 629*root.minSize
        y: 145*root.minSize
        width: 130*root.minSize
        height: 50*root.minSize
        nameText: qsTr("保存参数")
        nameFontpixelSize: 25*Math.min(root.width/850, root.height/580)
        onClicked: {
            function writeModSingal(handle, sqlName, min, max, point)
            {
                if(handle === "???") return
                var t_var = Number(handle)*Math.pow(10, point)
                if(t_var >= min && t_var <= max)
                    $modbusInterface.sl_modbusWriteData($sqlMcDefine.qml_queryTableRegDef(sqlName), t_var.toFixed(0))
            }
            writeModSingal(diffAdj_a.text, "A套调差值", -20000, 20000, 3)
            timerA_ass.start()
        }
        Timer{
            id:timerA_ass
            interval: 700
            repeat: true
            triggeredOnStart: false
            property int thisCounter: 0
            onTriggered: {
                refurbishA()
                thisCounter++
                if(thisCounter>3) {
                    thisCounter=0
                    stop()
                }
            }
        }
    }



    Text {
        x: 130*root.minSize
        y: 292*root.minSize
        color: "#44F6F6"
        text: qsTr("B通道调差值:")
        font.family: "Verdana"
        font.bold: true
        font.pixelSize: parent.textSize
    }

    TextInput {
        id:diffAdj_b
        x: 450*root.minSize
        y: 292*root.minSize
        color: "#bccc5a"
        text: qsTr("???")
        validator: RegExpValidator{regExp:/[0-9\.]+/}
        selectByMouse: true
        font.family: "Verdana"
        font.bold: true
        font.pixelSize: parent.textSize
    }

    EXC_Normal_BtnUncheckSecret_highStyle {
        id: eXC_Normal_BtnUncheckStyle1
        x: 629*root.minSize
        y: 291*root.minSize
        width: 130*root.minSize
        height: 50*root.minSize
        nameText: qsTr("保存参数")
        nameFontpixelSize: 25*Math.min(root.width/850, root.height/580)
        onClicked: {
            function writeModSingal(handle, sqlName, min, max, point)
            {
                if(handle === "???") return
                var t_var = Number(handle)*Math.pow(10, point)
                if(t_var >= min && t_var <= max)
                    $modbusInterface.sl_modbusWriteData($sqlMcDefine.qml_queryTableRegDef(sqlName), t_var.toFixed(0))
            }
            writeModSingal(diffAdj_b.text, "B套调差值", -20000, 20000, 3)
            timerB_ass.start()
        }
        Timer{
            id:timerB_ass
            interval: 700
            repeat: true
            triggeredOnStart: false
            property int thisCounter: 0
            onTriggered: {
                refurbishB()
                thisCounter++
                if(thisCounter>3) {
                    thisCounter=0
                    stop()
                }
            }
        }
    }

    EXC_Normal_BtnUncheckStyle {
        id: button3
        nameText: qsTr("返回")
        nameFontpixelSize: 30*Math.min(root.width/850, root.height/580)
        width: parent.width*0.15
        height: parent.height*0.09
        anchors.leftMargin: 420*root.minSize
        anchors.topMargin: 500*root.minSize
        anchors.left: parent.left
        anchors.top: parent.top
        onClicked: {
            sw.currentIndex = 0
        }
    }
}
